package com.iman.manjusri.web.home;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang3.math.NumberUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.iman.common.support.Page;
import com.iman.manjusri.service.BlogService;
import com.iman.manjusri.vo.BlogVo;
import com.iman.manjusri.web.BaseController;

@Controller
@RequestMapping(value = "/home/*")
public class SpaceBwHomController extends BaseController {

	@Autowired
	private BlogService blogService;

	@RequestMapping(value = "/bw")
	public ModelAndView resourceMore(HttpServletRequest request)
			throws Exception {

		Map<String, Object> model = new HashMap<String, Object>();
		String type = request.getParameter("operType");
		String ps = request.getParameter("ps");
		String pn = request.getParameter("pn");
		Page<BlogVo> pageDatas = null;
		int itype = NumberUtils.toInt(type, 1);
		int ipn = NumberUtils.toInt(pn, 1);
		int ips = NumberUtils.toInt(ps, 10);

		ModelAndView view = null;
		switch (itype) {
		case 1:
			view = new ModelAndView("home/blog_qb");
			break;
		case 2:
			view = new ModelAndView("home/blog_tj");
			break;
		default:
			view = new ModelAndView("home/blog_jh");
			break;
		}

		pageDatas = blogService.getBlogList(itype, ips, ipn);
		view.addObject("pageData", pageDatas);

		putResourceSrc(view);
		return view;
	}

}
